<?php
include ("include/dbconnect.php");
$sql = "SELECT * FROM bar ORDER BY idBar DESC";
$req = mysql_query($sql);
if (mysql_num_rows($req) == 0) {
    echo "Aucune ligne trouvée, rien à afficher.";
}
$j=1;
while($j<6 && $data = mysql_fetch_assoc($req)){
    ${'lastadd'.$j}= $data['name'];
    $j = $j + 1;
};
mysql_free_result($req);

$sql = "SELECT * FROM bar ORDER BY note DESC";
$req = mysql_query($sql);
if (mysql_num_rows($req) == 0) {
    echo "Aucune ligne trouvée, rien à afficher.";
}
$j=1;
while($j<6 && $data = mysql_fetch_assoc($req)){
    ${'rankbar'.$j}= $data['name'];
    $j = $j + 1;
};
mysql_free_result($req);

$sql = "SELECT * FROM bar ORDER BY note DESC";
$req = mysql_query($sql);
$j=1;
while($j<6 && $data = mysql_fetch_assoc($req)){
    ${'note'.$j}= $data['note'];
    $j = $j + 1;
};
mysql_free_result($req);
?>
<!DOCTYPE HTML>
<html>
    <div id="list">   
        <TABLE BORDER="15" WIDTH=90% HEIGHT="400px" ALIGN=CENTER> 
            <CAPTION> Dernier bar ajouté: </CAPTION> 
            <TR> 
                <TH> 1 </TH> 
                <TD> <?php if($lastadd1){echo $lastadd1;} ?> </TD>  
            </TR> 
            <TR> 
                <TH> 2 </TH> 
                <TD> <?php  if($lastadd2){echo $lastadd2;} {}?> </TD> 
            </TR>
            <TR> 
                <TH> 3 </TH> 
                <TD> <?php  if($lastadd3){echo $lastadd3;} ?> </TD> 
            </TR> 
            <TR> 
                <TH> 4 </TH> 
                <TD> <?php  if($lastadd4){echo $lastadd4;} ?> </TD> 
            </TR> 
            <TR> 
                <TH> 5 </TH> 
                <TD> <?php  if($lastadd5){echo $lastadd5;} ?> </TD> 
            </TR> 
        </TABLE> 
    </div>
    <div id="list">
        <TABLE BORDER="15" WIDTH=80% HEIGHT="400px" ALIGN=CENTER> 
            <CAPTION> Meilleur bar : </CAPTION> 
            <TR> 
                <TH> <?php if($rankbar1){echo $rankbar1;} ?> </TH> 
                <TD> <?php if($note1){echo $note1 . "/10";} ?> </TD>  
            </TR> 
            <TR> 
                <TH> <?php if($rankbar2){echo $rankbar2;} ?> </TH> 
                <TD> <?php if($note2){echo $note2 . "/10";} ?> </TD> 
            </TR>
            <TR> 
                <TH> <?php if($rankbar3){echo $rankbar3;} ?> </TH> 
                <TD> <?php if($note3){echo $note3 . "/10";} ?> </TD> 
            </TR> 
            <TR> 
                <TH> <?php if($rankbar4){echo $rankbar4;} ?> </TH> 
                <TD> <?php if($note4){echo $note4 . "/10";} ?> </TD> 
            </TR> 
            <TR> 
                <TH> <?php if($rankbar5){echo $rankbar5;} ?> </TH> 
                <TD> <?php if($note5){echo $note5 . "/10";} ?> </TD> 
            </TR> 
        </TABLE>
    </div>
</html>
